package swing;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
//import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JFrameEstudiante extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel panEstudiante;
	private JTextField txtCedula;
	private JTextField txtNombre;
	private JLabel lblNota;
	private JButton btnNuevo;
	private JButton btnEliminar;
	private JButton btnBuscar;
	private JButton btnRegistrar;
	private JTextField txtApellido;
	private JFormattedTextField jFormattedTextField;
	private JButton jbtnsalir;
	private JLabel lblLogo;
	private JFormattedTextField jFormattedTextFieldSeccion;
	private JTextField txtNota;
	private JLabel lblApellido;
	private JLabel lblNombre;
	private JLabel lblCedula;
	static JFrameCrearSeccion jfseccion = new JFrameCrearSeccion();
	
	public JFrameEstudiante() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				setTitle("Gestionar Estudiante");
				panEstudiante = new JPanel();
				getContentPane().add(panEstudiante, BorderLayout.CENTER);
				GroupLayout panEstudianteLayout = new GroupLayout((JComponent)panEstudiante);
				panEstudiante.setLayout(panEstudianteLayout);
				panEstudiante.setPreferredSize(new java.awt.Dimension(374, 332));
				panEstudiante.setBackground(new java.awt.Color(255,255,255));
				panEstudiante.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						System.out.println("panEstudiante.mouseClicked, event="+evt);
						//TODO add your code for panEstudiante.mouseClicked
					}
				});
				{
					lblCedula = new JLabel();
					lblCedula.setText("Cedula:");
				}
				{
					txtCedula = new JTextField();
				}
				{
					lblNombre = new JLabel();
					lblNombre.setText("Nombre:");
				}
				{
					lblApellido = new JLabel();
					lblApellido.setText("Apellido:");
				}
				{
					jFormattedTextField = new JFormattedTextField();
					jFormattedTextField.setEditable(false);
					jFormattedTextField.setBackground(new java.awt.Color(24,87,227));
				}
				{
					jbtnsalir = new JButton();
					jbtnsalir.setIcon(new ImageIcon(getClass().getResource("salir.jpeg")));
					jbtnsalir.setBackground(new java.awt.Color(255,255,255));
					//jbtnsalir.setText("Salir");
					jbtnsalir.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							System.out.println("jbtnsalir.mouseClicked, event="+evt);
							
							//TODO add your code for btnEstudiante.mouseClicked
							JFrameMenu jfest = new JFrameMenu();
		    				 jfest.setLocationRelativeTo(null);
		    				 jfest.setVisible(true);
		    				 setVisible(false);
						}
					});
				}
				{
					jFormattedTextFieldSeccion = new JFormattedTextField();
					jFormattedTextFieldSeccion.setText("Acciones Sobre el Estudiante");
					jFormattedTextFieldSeccion.setEditable(false);
					jFormattedTextFieldSeccion.setBackground(new java.awt.Color(24,87,227));
					jFormattedTextFieldSeccion.setForeground(new java.awt.Color(255,255,255));
					jFormattedTextFieldSeccion.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
				}
				{
					lblLogo = new JLabel();
					lblLogo.setIcon(new ImageIcon(getClass().getResource("escudo.jpeg")));
				}
				{
					lblNota = new JLabel();
					lblNota.setText("Nota:");
					
				}
				{
					txtNota = new JTextField();
					
				}

				{
					btnBuscar = new JButton();
					btnBuscar.setIcon(new ImageIcon(getClass().getResource("buscar.jpeg")));
					btnBuscar.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					//btnBuscar.setText("Buscar");
					btnBuscar.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							
							//TODO add your code for btnBuscar.mouseClicked
							
							btnNuevo.setEnabled(true);
							if(JFrameCrearSeccion.secc.buscar(txtCedula.getText())==true)
							{
								btnEliminar.setEnabled(true);
								txtCedula.setEditable(false);
								txtNombre.setEditable(false);
								txtApellido.setEditable(false);
								txtNota.setVisible(true);
								lblNota.setVisible(true);
								txtNota.setEditable(false);
								System.out.println("...");
								Estudiante e = JFrameCrearSeccion.secc.buscarEstudiante(txtCedula.getText());
								txtNombre.setText(e.getNombre());
								txtApellido.setText(e.getApellido());
								txtNota.setText(String.valueOf(e.getNotaFinal()));
							}
							else
							{
								btnEliminar.setEnabled(false);
							    btnRegistrar.setEnabled(true);
								JOptionPane.showMessageDialog(null," El Estudiante no se encuentra inscrito", "Busqueda de registro",JOptionPane.INFORMATION_MESSAGE);
							}
						}
					});
				}
				{
					btnEliminar = new JButton();
					btnEliminar.setIcon(new ImageIcon(getClass().getResource("eliminar.jpeg")));
					btnEliminar.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					//btnEliminar.setText("Eliminar");
					btnEliminar.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							System.out.println("btnEliminar.mouseClicked, event="+evt);
							//TODO add your code for btnEliminar.mouseClicked
						
							if(JFrameCrearSeccion.secc.buscar(txtCedula.getText()))
							{
								
								Estudiante e = JFrameCrearSeccion.secc.buscarEstudiante(txtCedula.getText());
								txtNombre.setText(e.getNombre());
								txtApellido.setText(e.getApellido());	
							
							
							JOptionPane.showMessageDialog(null,"El Estudiante ha sido retirado Exitosamente ", "Retiro de registro",JOptionPane.INFORMATION_MESSAGE);
							JFrameCrearSeccion.secc.retirarEstudiante(txtCedula.getText());
							txtCedula.setText("");
							txtNombre.setText("");
							txtApellido.setText("");
							btnRegistrar.setEnabled(true);
							txtCedula.setEditable(true);
							txtNombre.setEditable(true);
							txtApellido.setEditable(true);
							btnBuscar.setEnabled(true);
							btnEliminar.setEnabled(false);
					
							}
							else{
							JOptionPane.showMessageDialog(null,"El Estudiante no se encuentra registrado ", "Retiro de registro",JOptionPane.INFORMATION_MESSAGE);
							btnRegistrar.setEnabled(true);
							txtCedula.setEditable(true);
							txtNombre.setEditable(true);
							txtApellido.setEditable(true);
							btnBuscar.setEnabled(true);
							btnEliminar.setEnabled(false);
							}
						}
					});
				}
				
				{
					btnNuevo = new JButton();
					btnNuevo.setIcon(new ImageIcon(getClass().getResource("nuevos.jpeg")));
					btnNuevo.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					//btnNuevo.setText("Nuevo");
					btnNuevo.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							System.out.println("btnNuevo.mouseClicked, event="+evt);
							//TODO add your code for btnNuevo.mouseClicked
							txtCedula.setText("");
							txtNombre.setText("");
							txtApellido.setText("");
							btnRegistrar.setEnabled(true);
							txtCedula.setEditable(true);
							txtNombre.setEditable(true);
							txtApellido.setEditable(true);
							btnBuscar.setEnabled(true);
							btnEliminar.setEnabled(false);
						}
					});
				}
				
				{
					txtApellido = new JTextField();
				}
				
				{
					btnRegistrar = new JButton();
					btnRegistrar.setIcon(new ImageIcon(getClass().getResource("agregar.jpeg")));
					btnRegistrar.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));

					btnRegistrar.addMouseListener(new MouseAdapter() {
						
						public void mouseClicked(MouseEvent evt) {
							// txtNota.setVisible(false);
						     //lblNota.setVisible(false);
							//TODO add your code for btnRegistrar.mouseClicked
							 if(( txtCedula.getText().length() == 0) ||txtCedula.getText().length()!=8 || txtNombre.getText().length() == 0 || txtApellido.getText().length() == 0){
								
							 	 JOptionPane.showMessageDialog(null," Debe llenar todos los campos e introduzca una cedula con 8 dígitos", "Registro de Estudiante",JOptionPane.INFORMATION_MESSAGE);
							 }
							 else if (JFrameCrearSeccion.secc.getProfesor().getCedula().compareTo(txtCedula.getText())==0)
							     JOptionPane.showMessageDialog(null,"Verifique: La Cedula ya corresponde al profesor de la sección", "Registro de Estudiante",JOptionPane.INFORMATION_MESSAGE);
							 else if(JFrameCrearSeccion.secc.buscar(txtCedula.getText())==false){
							     
								 Estudiante est= new Estudiante(txtCedula.getText(), txtNombre.getText(), txtApellido.getText());
							 	 JFrameCrearSeccion.secc.inscribirEstudiante(est);
							     JOptionPane.showMessageDialog(null,"El Estudiante ha sido Registrado Exitosamente ", "Registro de Estudiante",JOptionPane.INFORMATION_MESSAGE);
							     txtCedula.setText("");
							     txtNombre.setText("");
							     txtApellido.setText("");
							     lblNota.setVisible(false);
							     txtNota.setVisible(false);
							     
							   /*  JFrameAccionSeccion jfaccseccion = new JFrameAccionSeccion();
							     jfaccseccion.setLocationRelativeTo(null);
							     jfaccseccion.setVisible(true);
							     setVisible(false);*/
							     
							     
					         if (JFrameCrearSeccion.secc.getAlumnos().size()>4){		     
							     JFrameReporteOrdenadosNotaFinal jfordenadosnota = new JFrameReporteOrdenadosNotaFinal();
							     jfordenadosnota.setLocationRelativeTo(null);
							     jfordenadosnota.setVisible(true);
							     setVisible(false);
					         }
						     }
							 else 
						         JOptionPane.showMessageDialog(null,"El Estudiante ya se encuentra registrado ", "Registro de Estudiante",JOptionPane.INFORMATION_MESSAGE);	
						}
					});
					
				}
				
				{
					txtNombre = new JTextField();
				}

				panEstudianteLayout.setHorizontalGroup(panEstudianteLayout.createSequentialGroup()
					.addContainerGap(20, 20)
					.addGroup(panEstudianteLayout.createParallelGroup()
					    .addGroup(panEstudianteLayout.createSequentialGroup()
					        .addComponent(jFormattedTextField, GroupLayout.PREFERRED_SIZE, 320, GroupLayout.PREFERRED_SIZE)
					        .addGap(0, 0, Short.MAX_VALUE))
					    .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					        .addComponent(lblLogo, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addComponent(jFormattedTextFieldSeccion, GroupLayout.PREFERRED_SIZE, 264, GroupLayout.PREFERRED_SIZE)
					        .addGap(0, 0, Short.MAX_VALUE))
					    .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					        .addGap(27)
					        .addGroup(panEstudianteLayout.createParallelGroup()
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addComponent(lblNota, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
					                .addGap(19))
					            .addComponent(lblCedula, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
					            .addComponent(lblNombre, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
					            .addComponent(lblApellido, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addGap(16)
					                .addComponent(btnRegistrar, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
					                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)))
					        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					        .addGroup(panEstudianteLayout.createParallelGroup()
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addComponent(btnBuscar, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
					                .addGap(17)
					                .addComponent(btnEliminar, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
					                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					                .addComponent(btnNuevo, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addComponent(txtNombre, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
					                .addGap(31))
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addComponent(txtNota, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
					                .addGap(31))
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addComponent(txtApellido, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
					                .addGap(31))
					            .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					                .addComponent(txtCedula, GroupLayout.PREFERRED_SIZE, 121, GroupLayout.PREFERRED_SIZE)
					                .addGap(31)))
					        .addGap(17)
					        .addComponent(jbtnsalir, GroupLayout.PREFERRED_SIZE, 43, GroupLayout.PREFERRED_SIZE)
					        .addGap(0, 12, Short.MAX_VALUE)))
					.addContainerGap(36, 36));
				panEstudianteLayout.setVerticalGroup(panEstudianteLayout.createSequentialGroup()
					.addGroup(panEstudianteLayout.createParallelGroup()
					    .addComponent(lblLogo, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					        .addGap(32)
					        .addComponent(jFormattedTextFieldSeccion, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					        .addGap(34)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(panEstudianteLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(txtCedula, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(lblCedula, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(panEstudianteLayout.createParallelGroup()
					    .addComponent(txtNombre, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addGroup(GroupLayout.Alignment.LEADING, panEstudianteLayout.createSequentialGroup()
					        .addGap(12)
					        .addComponent(lblNombre, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(panEstudianteLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(txtApellido, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(lblApellido, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
					.addGroup(panEstudianteLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(txtNota, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
					    .addComponent(lblNota, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(20)
					.addComponent(jFormattedTextField, GroupLayout.PREFERRED_SIZE, 13, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(panEstudianteLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
					    .addComponent(btnBuscar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
					    .addComponent(btnEliminar, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
					    .addComponent(btnNuevo, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
					    .addComponent(btnRegistrar, GroupLayout.Alignment.BASELINE, 0, 44, Short.MAX_VALUE)
					    .addComponent(jbtnsalir, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(15, 15));
			}
			pack();
			this.setSize(378, 361);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
